package com.ivr.cm.dao.impl;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.ivr.cm.dao.IUserBehaviorDao;
import com.ivr.cm.service.BaseServiceIF;
import com.ivr.cm.util.BaseUtil;
import com.ivr.cm.vo.UserBehaviorVo;

/**
 * 用户行为数据接口
 * @author liugeng
 * @date 2015-12-15
 * @version 1.0
 */
public class UserBehaviorDaoImpl extends JdbcDaoSupport implements IUserBehaviorDao,BaseServiceIF<Object> {
	private static Logger logger = Logger.getLogger(UserBehaviorDaoImpl.class);
	
	@Override
	public int doProcess(Object obj) {
		if(obj instanceof UserBehaviorVo){
			return insertUserBehavior((UserBehaviorVo)obj);
		}
		return 0;
	}
	
	/**保存用户行为记录*/
	@Override
	public int insertUserBehavior(UserBehaviorVo userBehaviorVo) {
		String sql = "insert into tb_ivr_user_behavior(mobile,sp_number,province,city,pressed,add_date) values(?,?,?,?,?,now())";
		Object[] param = new Object[]{userBehaviorVo.getMobile(),userBehaviorVo.getSp_number(),
									userBehaviorVo.getProvince(),userBehaviorVo.getCity(),
									userBehaviorVo.getPressed()};
		logger.info(String.format("[%s][%s]保存用户行为记录[%s]", userBehaviorVo.getMobile(),userBehaviorVo.getSp_number(), BaseUtil.logSQL(sql, param)));
		int result = this.getJdbcTemplate().update(sql, param);
		
		return result;
	}
}
